package com.hippo.core.ui.components

import androidx.compose.foundation.Image
import androidx.compose.foundation.clickable
import androidx.compose.foundation.interaction.MutableInteractionSource
import androidx.compose.foundation.interaction.collectIsPressedAsState
import androidx.compose.runtime.Composable
import androidx.compose.runtime.getValue
import androidx.compose.runtime.remember
import androidx.compose.ui.Modifier
import androidx.compose.ui.res.painterResource

@Composable
fun ImageButton(
    modifier: Modifier = Modifier,
    pressedImageRes: Int,
    defaultImageRes: Int,
    onClick: (() -> Unit) = {}
) {

    val interactionSource = remember { MutableInteractionSource() }
    val isPressed by interactionSource.collectIsPressedAsState()

    Image(
        painter = painterResource(id = if (isPressed) pressedImageRes else defaultImageRes),
        contentDescription = null,
        modifier = modifier
            .clickable(
                interactionSource = interactionSource,
                indication = null // 可以设置为 null 以移除默认的点击效果
            ) {
                onClick()
            }
    )


}